import { PipeTransform, Injectable, ArgumentMetadata } from '@nestjs/common';

@Injectable()
export class FileNameEncodePipe implements PipeTransform {
  transform(value: Express.Multer.File, metadata: ArgumentMetadata) {
    //可以在这块验证文件

    //修改文件名为中文
    if (!/[^\u0000-\u00ff]/.test(value.originalname)) {
      value.originalname = Buffer.from(value.originalname, 'latin1').toString(
        'utf8',
      );
    }
    return value;
  }
}
